﻿using FluentNHibernate.Conventions;
using FluentNHibernate.Conventions.Instances;
using NHibernate.Sidekick.Utils.Extensions;

namespace NHibernate.Sidekick.Utils.MappingConventions
{
    /// <summary>
    /// Formats the class' name from camelCase to Under_Score naming.
    /// </summary>
    public class CamelCaseToUnderscoreNamingConvention : IClassConvention, IPropertyConvention
    {
        /// <summary>
        /// Apply changes to the target.
        /// </summary>
        /// <param name="instance"></param>
        public void Apply(IClassInstance instance)
        {
            instance.Table(instance.EntityType.Name.ToUnderscoredNaming());
        }

        /// <summary>
        /// Apply changes to the target.
        /// </summary>
        /// <param name="instance"></param>
        public void Apply(IPropertyInstance instance)
        {
            instance.Column(instance.Property.Name.ToUnderscoredNaming());
        }
    }
}